package com.five.wisdomEat.controller;

import cn.hutool.core.date.DateTime;
import com.five.wisdomEat.entity.Announcement;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    private AnnouncementService service;

    @GetMapping("/getAnnouncementList")
    public ResponseMessage selectAnnouncementList(){
        return service.selectAnnouncementList();
    }

    @PostMapping("/insertAnnouncement")
    public ResponseMessage insertAnnouncement(String aContent){
        Announcement announcement = new Announcement();
        announcement.setAContent(aContent);
        announcement.setATime(new DateTime());
        return service.insertAnnouncement(announcement);
    }

    @PostMapping("/updateAnnouncement")
    public ResponseMessage updateBusiness(Integer id,String aContent){
        Announcement announcement = new Announcement();
        announcement.setId(id);
        announcement.setAContent(aContent);
        announcement.setATime(new DateTime());
        return service.updateAnnouncement(announcement);
    }

    @PostMapping("/deleteAnnouncement")
    public ResponseMessage deleteBusiness(Integer id){
        return service.deleteAnnouncement(id);
    }
}
